package cj.web.marry.dao;

import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;

@DAO
public interface RegDAO {
	
	@SQL("SELECT id,code,man,manCard,woman,womanCard,regTime,link,addressId,createAt,type,status,memo FROM MarriageReg WHERE link=:1 ORDER BY createAt desc")
	List<Map> queryRegByLink(String link);
	
	@SQL("SELECT id,code,man,manCard,woman,womanCard,regTime,link,addressId,createAt,type,status,memo FROM MarriageReg WHERE link=:1 and status!=3 ORDER BY createAt DESC")
	List<Map> repeatRegByLink(String link);

	@SQL("SELECT id,code,name,descs FROM SetMeal WHERE deleteFlag = 1")
	List<Map> setMeals();

	@SQL("INSERT INTO MarriageReg (code,man,manCard,woman,womanCard,regTime,link,addressId,createAt,type,status) VALUES (:1,:2,:3,:4,:5,:6,:7,:8,now(),:9,:10)")
	void create(String code, String man, String manCard, String woman,String womanCard, String regTime, String link, 
			String addressId, String type, int status);

	@SQL("INSERT INTO MarriageReg (code,man,manCard,woman,womanCard,regTime,link,addressId,createAt,type,status,manType,womanType,manRegistry,womanRegistry) VALUES (:1,:2,:3,:4,:5,:6,:7,:8,now(),:9,:10,:11,:12,:13,:14)")
	void createNew(String code, String man, String manCard, String woman,String womanCard, String regTime, String link, 
			String addressId, String type, int status,int manType,int womanType,String manRegistry,String womanRegistry);

	@SQL("SELECT count(1) FROM MarriageReg where manCard in (:1,:2)  AND type=:3 AND status=1 AND regTime > now()")
	int repeatMan(String manCard, String womanCard,String type);
	
	@SQL("SELECT count(1) FROM MarriageReg where womanCard in (:1,:2)  AND type=:3 AND status=1 AND regTime > now()")
	int repeatWoman(String manCard, String womanCard,String type);
	
	@SQL("select id from UserApplication where openid=:1")
    String getCode(String openid);

	@SQL("SELECT count(1) FROM MarriageReg WHERE man=:1 AND link=:2 AND type=:3  AND status=1 AND regTime > now()")
	int repeat(String man, String link, int type);

	@SQL("INSERT INTO MarriageReg (code,man,regTime,link,addressId,type,status,setMealId,createAt) VALUES (:1,:2,:3,:4,:5,:6,:7,:8,now())")
	void order(String code, String man, String regTime, String link,
			String addressId, int type, int status,String setMealId);
}
